import http from "@/http";

export default {
  loadSelects(success) {
    http.get("material/load/infos", {}, success);
  },
  /**
   * 原料列表
   * @param {number} page  页码
   * @param {Function} success 回调
   */
  list(page, success) {
    http.get(
      "material/list",
      {
        page: page
      },
      success
    );
  },

  areas(success) {
    http.get("area/all", {}, success);
  },
  /**
   * 原料检索
   * @param {number} page 页码
   * @param {string} key 关键词
   * @param {Function} success 回调
   */
  search(page, key, success) {
    http.get(
      "material/search",
      {
        page: page,
        key: key
      },
      success
    );
  },
  /**
   * 添加原料
   * @param {Object} material 原料
   * @param {Function} success 回调
   */
  save(material, success) {
    http.postBody("material/add", material, success);
  },
  /**
   * 更新原料
   * @param {Object} material 原料
   * @param {Function} success 回调
   */
  update(material, success) {
    http.postBody("material/edit", material, success);
  },
  /**
   * 删除原料
   * @param {number} id 原料id
   * @param {Function} success 回调
   */
  delete(id, success) {
    http.get("material/delete/" + id, success);
  }
};
